<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>添加医生</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <script src="./js/jquery.min.js"></script>
        <script src="./js/jquery-form.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" enctype="multipart/form-data" id="go">
                  <div class="layui-form-item">
                      <label for="account" class="layui-form-label">
                          <span class="x-red">*</span>账号
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="account" name="account" required="" lay-verify="account"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为您唯一的登陆账号
                      </div>
                  </div>

                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          6到16个字符
                      </div>
                  </div>

                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          <span class="x-red">*</span>确认密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_repass" name="password" required="" lay-verify="repass"
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>


                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            名称
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" required="" lay-verify="name"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="identity" class="layui-form-label">
                            <span class="x-red">*</span>身份证
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="identity" name="identity" required="" lay-verify="identity"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="nation" class="layui-form-label">
                            民族
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="nation" name="nation" required="" lay-verify="nation"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="introduction" class="layui-form-label">
                            简介
                        </label>
                        <div class="layui-input-inline">
                            <textarea id="introduction" name="introduction" required="" lay-verify="introduction" autocomplete="off" class="layui-input">
                                </textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="pic" class="layui-form-label">
                            照片
                        </label>
                        <div class="layui-input-inline">
                            <input type="file" id="pic" name="file" required="" lay-verify="pic"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="phone" class="layui-form-label">
                            手机号码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" required="" lay-verify="phone"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label for="departmentsId" class="layui-form-label">
                            一级科室
                        </label>
                        <div class="layui-input-inline">
                            <select type="text" id="departmentsId" name="departmentsId" required="" lay-filter="departmentsId"
                                   autocomplete="off" class="layui-input">
                                    <option value="0">请选择</option>

                            </select>
                        </div>
                        <label for="dieseaseId" class="layui-form-label">
                            二级科室
                        </label>
                        <div class="layui-input-inline">
                            <select type="text" id="dieseaseId" name="dieseaseId" required="" lay-verity="dieseaseId"
                                    autocomplete="off" class="layui-input">
                                <option value="0">请选择</option>

                            </select>
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">医生等级</label>
                        <div class="layui-input-block">
                            <input type="radio" name="doctorGrage" lay-skin="primary" title="普通"  value="0" checked>
                            <input type="radio" name="doctorGrage" lay-skin="primary" title="专家" value="1">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="sex" lay-skin="primary" title="男"  value="0" checked>
                            <input type="radio" name="sex" lay-skin="primary" title="女" value="1">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                        <div class="layui-input-block">
                            <input type="radio" name="roleId" lay-skin="primary" title="主任医师"  value="1">
                            <input type="radio" name="roleId" lay-skin="primary" title="副主任医生" value="2">
                            <input type="radio" name="roleId" lay-skin="primary" title="医师" value="3" checked="">
                        </div>
                    </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          增加
                      </button>
                  </div>
              </form>
            </div>
        </div>
        <script>
            var token =  localStorage.getItem("token");
            var  head = new Headers();
            head.append('token',token);
            $(function () {
                $.ajax({
                    type:"post",
                    url:"/hospital/api/back/departments/getDepartments1",
                    dataType:"json",
                    async: false,
                    headers: {
                        'token':token
                    },
                    success:function(msg){
                        var user= msg.data;
                        for(var i = 0;i<user.length;i++){
                            //alert(user[i].tdepartmentsId+user[i].tdepartmentsName);  dieseaseId
                            $("#departmentsId").append("<option value="+user[i].departmentsId+">"+user[i].departmentsName+"</option>" );
                        }
                    }
                });





            });



            layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;



                form.on('select(departmentsId)', function(data){


                    $.ajax({
                        type:"post",
                        url:"/hospital/api/back/departments/getTdepartments1",
                        dataType:"json",
                        data:{"departmentsId":data.value},
                        async: false,
                        headers: {
                            'token':token
                        },
                        success:function(msg){
                            var user= msg.data;
                            console.log(user);
                            $("#dieseaseId").html("");
                            for(var i = 0;i<user.length;i++){
                               // alert("qqqqq"+user[i].tdepartmentsName);
                                //alert(user[i].tdepartmentsId+user[i].tdepartmentsName);  dieseaseId
                                $("select[name='dieseaseId']").append("<option value="+user[i].tdepartmentsId+">"+user[i].tdepartmentsName+"</option>" );
                                form.render('select');//  注意：数据赋值完成之后必须调用该方法，进行layui的渲染，否则数据出不来


                            }
                        }
                    });
                });

                var status="";

                $("#account").blur(function () {
                    var account = $("#account").val();
                    $.ajax({
                        url:"/hospital/api/back/doctor/exist",
                        type:"post",
                        dataType:"json",
                        headers: {
                            'token':token
                        },
                        data:{
                            "account": account
                        },
                        success:function (msg) {
                            if(msg.code==0){
                                status="exist";
                            }
                        }
                    });
                });

                //自定义验证规则
                form.verify({
                    account: function(value) {
                        if (value.length < 5) {
                            return '账号至少要5个字符啊';
                        }


                        if(status=="exist"){
                            return '账号已存在';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    },

                });

                //监听提交

                $('#go').submit(function() {
                    $(this).ajaxSubmit({

                        //beforeSubmit: showRequest,  //提交前的回调函数，一般用作提交前的表单验证
                        success: function (data) {
                            if (msg.code == 0) {
                                layer.alert("增加成功", {
                                        icon: 6
                                    },
                                    function () {
                                        //关闭当前frame
                                        xadmin.close();

                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            } else {
                                layer.msg("添加失败！");
                            }
                        },      //提交后的回调函数
                        url: "/hospital/api/back/doctor/add",                 //默认是form的action， 如果申明，则会覆盖
                        type: "post",               //默认是form的method（get or post），如果申明，则会覆盖
                        dataType: "json",           //html(默认), xml, script, json...接受服务端返回的类型
                        headers: {
                            'token':token
                        },
                        //clearForm: true,          //成功提交后，清除所有表单元素的值
                        //resetForm: true,          //成功提交后，重置所有表单元素的值
                        //timeout: 3000               //限制请求的时间，当请求大于3秒后，跳出请求
                    });


                });

            });</script>

    </body>

</html>
